package com.yicong.ants.ui.me;

import android.view.View;

import com.cchao.simplelib.core.RxHelper;
import com.cchao.simplelib.ui.activity.BaseTitleBarActivity;
import com.cchao.simplelib.util.StringHelper;
import com.yicong.ants.R;
import com.yicong.ants.databinding.FeedBackActivityBinding;
import com.yicong.ants.manager.UserManager;
import com.yicong.ants.manager.http.RetrofitHelper;

import java.util.HashMap;
import java.util.Map;

/**
 * @author cchao
 * @version 2019-07-11.
 */
public class FeedBackActivity extends BaseTitleBarActivity<FeedBackActivityBinding> implements View.OnClickListener {
    @Override
    protected int getLayout() {
        return R.layout.feed_back_activity;
    }

    @Override
    protected void initEventAndData() {
        setTitleText("意见反馈");
        mDataBind.setClick(this);
        if (UserManager.isLogin()) {
            mDataBind.mobile.setText(UserManager.getUserBean().getMobile());
        }
    }

    @Override
    protected void onLoadData() {}

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.apply:
                if (StringHelper.isEmpty(mDataBind.mobile)) {
                    showToast("请填写手机号");
                    return;
                }

                if (StringHelper.isEmpty(mDataBind.content)) {
                    showToast("请填写反馈内容");
                    return;
                }

                showProgress();
                Map<String, String> map = new HashMap<>();
                map.put("mobile", mDataBind.mobile.getText().toString());
                map.put("content", mDataBind.content.getText().toString());
                addSubscribe(RetrofitHelper.getApis().feedBack(map)
                    .compose(RxHelper.toMain())
                    .subscribe(respBean -> {
                        hideProgress();
                        showToast(respBean.getMsg());
                        if (respBean.isCodeFail()) {
                            return;
                        }
                        finish();
                    }, RxHelper.getHideProgressConsumer(this)));
                break;
        }
    }
}
